Xbasic

Array initialize_from_csv Method

Syntax

V <array>.initialize_from_csv(csvData as c[,hasFieldNames as l])

Arguments

csvDataCharacter

Comma separated value data, if there are commas in the data, it is expected that the comments are enclosed in quotes.

hasFieldNames Logical

Does the first row of the data define the field names for the data, default is false. If fieldnames are defined, type for field can be specified by included a type after a trailing:".

Description

Initialize a property array with from a passed in CSV string.

Example

dim txt as c 
txt = <<%txt%
ticker,name,price:N,change:N,mktcap,chgPct
"AAPL","Apple Inc.",402.215,"-24.025",377.7B,"-24.025 - -5.64%"
"GOOG","Google Inc.",780.37,"-13.00",257.3B,"-13.00 - -1.64%"
"MSFT","Microsoft Corpora",28.8349,"-0.1351",241.5B,"-0.1351 - -0.47%"
"INTC","Intel Corporation",22.067,"+0.152",109.1B,"+0.152 - +0.69%"
"HPQ","Hewlett-Packard C",20.48,"-0.55",39.814B,"-0.55 - -2.62%"
"ORCL","Oracle Corporatio",32.528,"-0.887",153.2B,"-0.887 - -2.65%"
"CSCO","Cisco Systems, In",20.625,"-0.535",110.0B,"-0.535 - -2.53%"
"DELL","Dell Inc.",14.005,"-0.035",24.470B,"-0.035 - -0.25%"
"YHOO","Yahoo! Inc.",23.696,"-0.094",26.096B,"-0.094 - -0.40%"
"FB","Facebook, Inc.",26.5912,"-0.3288",63.344B,"-0.3288 - -1.22%"
"LNKD","LinkedIn Corporat",180.29,"-2.18",19.661B,"-2.18 - -1.19%"
"GRPN","Groupon, Inc.",6.37,"-0.01",4.194B,"-0.01 - -0.16%"
"YELP","Yelp Inc. Class A",25.545,"-0.165",1.628B,"-0.165 - -0.64%"
%txt%

dim arr[0] as p
arr.initialize_from_csv(txt,.t.)
? arr[1]
= change = -24.025
chgPct = "-24.025 - -5.64%"
mktcap = "377.7B"
name = "Apple Inc."
price = 402.215
ticker = "AAPL"

? arr.size()
= 13

? arr.get_fields()
= ticker
name
price
change
mktcap
chgPct

format = stritran(arr.get_fields(),crlf(),"|")
? format
= "ticker|name|price|change|mktcap|chgPct"

? arr.dump_properties(format)
= AAPL|Apple Inc.|402.215|-24.025|377.7B|-24.025 - -5.64%
GOOG|Google Inc.|780.37|-13|257.3B|-13.00 - -1.64%
MSFT|Microsoft Corpora|28.8349|-0.1351|241.5B|-0.1351 - -0.47%
INTC|Intel Corporation|22.067|0.152|109.1B|+0.152 - +0.69%
HPQ|Hewlett-Packard C|20.48|-0.55|39.814B|-0.55 - -2.62%
ORCL|Oracle Corporatio|32.528|-0.887|153.2B|-0.887 - -2.65%
CSCO|Cisco Systems, In|20.625|-0.535|110.0B|-0.535 - -2.53%
DELL|Dell Inc.|14.005|-0.035|24.470B|-0.035 - -0.25%
YHOO|Yahoo! Inc.|23.696|-0.094|26.096B|-0.094 - -0.40%
FB|Facebook, Inc.|26.5912|-0.3288|63.344B|-0.3288 - -1.22%
LNKD|LinkedIn Corporat|180.29|-2.18|19.661B|-2.18 - -1.19%
GRPN|Groupon, Inc.|6.37|-0.01|4.194B|-0.01 - -0.16%
YELP|Yelp Inc. Class A|25.545|-0.165|1.628B|-0.165 - -0.64%

See Also